package com.rcl.mvvmdemo.domain

import com.rcl.mvvmdemo.api.ApiException

data class ResultData<T>(val success: Boolean, val code: Int, val message: String, val data: T) {
    companion object {
        const val CODE_SUCCESS = 10000
    }

    //如果是成功的code，我们就返回数据，否则就抛出异常
    fun apiData(): T {
        if (code == CODE_SUCCESS) {
            return data
        } else {
            throw ApiException(code, message)
        }
    }
}
